package com.sunshine.springboot.controller.thymeleaf;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * Thymeleaf 模板
 *
 * @author WeiHong
 * @date 2018/8/16
 */
@RestController
@RequestMapping("thymeleaf")
public class ThymeleafController {

    @GetMapping("index")
    public ModelAndView index(ModelAndView view) {
        view.addObject("title", "这是一个标题");
        view.addObject("content", "thymeleaf第一个网页");
        Author author = new Author();
        author.setAge(24);
        author.setName("WeiHong");
        view.addObject("author",author);
        view.setViewName("thymeleaf");
        return view;
    }

    @GetMapping("index1")
    public ModelAndView index1(ModelAndView view) {
        view.setViewName("thymeleaf");
        return view;
    }

    @Getter
    @Setter
    @ToString
    class Author {
        private String name;
        private Integer age;
    }
}
